var lon, lat, city, timerobj, timer;
mui.init({
	pullRefresh: {
		container: '#pullrefresh',
		down: { //下拉刷新
			callback: pulldownRefresh,
			style: mui.os.android ? "circle" : "default"
		}
	}
});
//定义图表
var option1 = {
	tooltip: {
		trigger: 'item',
		show: false
	},
	series: [{
			name: '故障',
			type: 'pie',
			radius: ['80%', '90%'],
			avoidLabelOverlap: false,
			label: {
                normal: {
                	formatter: '{d}%',
                    position: 'center',
                    textStyle: {
			            fontSize: '18',
			            fontWeight: 'bold',
			            color: '#fff'
			        }
                }
            },
			data: [{
				value: 63,
				itemStyle: {
					normal: {
						color: '#EACE36',
						label: {
							show: true
						},
						labelLine: {
							show: false
						}
					},
				},
			}, {
				value: 37,
				label: {
					show: false
				},
				labelLine: {
					show: false
				},
				itemStyle: {
					normal: {
						color: '#fbf4fe'
					},
				},
			}],
		},

	]
};
var option2 = {
	tooltip: {
		trigger: 'item',
		show: false
	},
	series: [{
			name: '在线单位',
			type: 'pie',
			radius: ['80%', '90%'],
			avoidLabelOverlap: false,
			label: {
                normal: {
                	formatter: '{d}%',
                    position: 'center',
                    textStyle: {
			            fontSize: '18',
			            fontWeight: 'bold',
			            color: '#fff'
			        }
                }
            },
			data: [{
				value: 9,
				itemStyle: {
					normal: {
						color: '#FB5E61',
						label: {
							show: true,
							position: 'center',
							formatter: '{c}%',
							textStyle: {
								color: '#f79a9a',
								fontSize: '40',
								fontWeight: 'bold',
							}
						},
						labelLine: {
							show: false
						}
					},
				},
			}, {
				value: 91,
				name: '',
				label: {
					show: false,
				},
				labelLine: {
					show: false
				},
				itemStyle: {
					normal: {
						color: '#fff7f7',
					},
				},
			}],
		},

	]
};
var option3 = {
	tooltip: {
		trigger: 'item',
		show: false
	},
	series: [{
			name: '在线单位',
			type: 'pie',
			radius: ['80%', '90%'],
			avoidLabelOverlap: false,
			label: {
                normal: {
                	formatter: '{d}%',
                    position: 'center',
                    textStyle: {
			            fontSize: '18',
			            fontWeight: 'bold',
			            color: '#fff'
			        }
                }
            },
			data: [{
				value: 26,
				label: {
					show: true,
				},
				
				itemStyle: {
					normal: {
						color: '#2aaf66'
					}
				}
			}, {
				value: 74,
				name: '',
				label: {
					show: false
				},
				labelLine: {
					show: false
				},
				itemStyle: {
					normal: {
						color: '#fff'
					},
				},
			}],
		},

	]
};
var pieChart1 = echarts.init(document.getElementById('pieChart1'));
pieChart1.setOption(option1);
var pieChart2 = echarts.init(document.getElementById('pieChart2'));
pieChart2.setOption(option2);
var pieChart3 = echarts.init(document.getElementById('pieChart3'));
pieChart3.setOption(option3);

document.getElementById('selectBegin').addEventListener('tap', function() {
	var _self = this;
	_self.picker = new mui.DtPicker({
		type: "date"
	});
	_self.picker.show(function(re) {
		_self.innerHTML = re.text;
	});
})
document.getElementById('selectEnd').addEventListener('tap', function() {
	var _self = this;
	_self.picker = new mui.DtPicker({
		type: "date"
	});
	_self.picker.show(function(re) {
		_self.innerHTML = re.text;
	});
})


mui.plusReady(function() {
	storage.init();
	//注册登录事件
	appPage.registerCheckLoginEvent();

	initPage();

	//	if(!storageLocation.Lon || storageLocation.Lon == "") { //未拿到定位信息
	//		plus.nativeUI.showWaiting("定位中...");
	//		plus.geolocation.getCurrentPosition(function(position) {
	//			plus.nativeUI.closeWaiting();
	//			storageLocation.refreshData(position);
	//			storageLocation.log();
	//			initPage();				
	//		}, function(e) {
	//			plus.nativeUI.closeWaiting();
	//			mui.alert(JSON.stringify(e));
	//			//appUI.showTopTip("定位失败，请手动选择位置"+JSON.stringify(e));
	//		}, {
	//			geocode: true
	//		});
	//	} else {
	//		initPage();
	//	}

})

function initPage() {
	lon = storageLocation.Lon;
	lat = storageLocation.Lat;
	city = storageLocation.City;
	//document.getElementById("city").innerText = city;

	loadData();
}
//下拉刷新具体业务实现
function pulldownRefresh() {
	loadData();
}
//一次性拉取数据
function loadData() {
	request("/Index/getIndexLis", {
		lon: lon,
		lat: lat,
		cityid: storageLocation.CityId
	}, function(json) {
		if (json.code == "0") {

		} else {
			appUI.showTopTip(json.msg)
		}
		appPage.endPullRefresh();
	}, false, function() {
		appPage.endPullRefresh();
		var arr = document.getElementsByClassName("nodata");
		for (var i = 0; i < arr.length; i++) {
			arr[i].innerText = "暂无数据";
		}
	});
}
